import { getAction, putAction, postAction } from '@/api/manage'
import * as DATARULE from '../rule/service.js'
import { serviceApi } from '@/api/common.js'
/**
 * 公共API接口
 */
export const api = {
  list: (appId) => serviceApi.auth + `/permissions/${appId}`,
  delete: (ids) => serviceApi.auth + `/permissions/${ids}`,
  deletePermRule: (id) => serviceApi.auth + `/permissions/data-rules/${id}`,
  permRuleList: serviceApi.auth + '/permissions/data-rules/perm-rules',
  dataRuleList: DATARULE.api.list

}

/**
 * 获取应用菜单
 * @param {*} params
 * @returns
 */
export const getSystemMenuList = (appId, params) => getAction(serviceApi.auth + `/permissions/${appId}`, params);
/**
 * 获取应用子菜单
 * @param {*} params
 * @returns
 */
export const getSystemSubmenu = (parentId, params) => getAction(serviceApi.auth + `/permissions/children/${parentId}`, params);
/**
 * 批量获取应用子菜单
 * @param {*} params
 * @returns
 */
export const getSystemSubmenuBatch = (params) => getAction(serviceApi.auth + '/permissions/children-batch', params);

/**
 * 添加菜单
 * @param {*} params
 * @returns
 */
export const addPermission = params => postAction(serviceApi.auth + '/permissions', params);

/**
 * 编辑菜单
 * @param {*} params
 * @returns
 */
export const editPermission = params => putAction(serviceApi.auth + '/permissions', params);

/**
 * 获取菜单列表
 * @param {*} params
 * @returns
 */
export const getPermissionList = (appId, params) => getAction(api.list(appId), params);

/**
 * 获取菜单树形列表
 * @param {*} params
 * @returns
 */
export const queryTreeList = (appId, params) => getAction(serviceApi.auth + `/permissions/map-tree/${appId}`, params);

/**
 * 通过菜单ID获取数规则
 * @param {*} params
 * @returns
 */
export const getPermissionRuleList = params => getAction(serviceApi.auth + '/permissions/data-rules/perm-rules', params);

/**
 * 查询数据规则列表
 * @param {*} params
 * @returns
 */
export const queryPermissionRule = params => getAction(serviceApi.auth + '/permissions/data-rules', params);

/**
 * 添加已选中的菜单
 * @param {*} params
 * @returns
 */
export const addPermissionBySelect = params => postAction(serviceApi.auth + '/permissions/data-rules/select-perm', params);

/**
 * 添加菜单数据权限
 * @param {*} params
 * @returns
 */
export const addPermissionRule = params => postAction(serviceApi.auth + '/permissions/data-rules', params);

/**
 * 编辑菜单数据权限
 * @param {*} params
 * @returns
 */
export const editPermissionRule = params => putAction(serviceApi.auth + '/permissions/data-rules', params);

export const queryListAsync = (pid, params) => getAction(serviceApi.auth + `/permissions/tree-async/${pid}`, params)
